////////////////////////////////////////////////////////////////////////////////
// Filename: cameraclass.cpp
////////////////////////////////////////////////////////////////////////////////
#include "Camera.h"


Camera::Camera()
{
	mPosition = XMFLOAT3(0, 0, 0);
	mUp = XMFLOAT3(0, 1, 0);
	mFront = XMFLOAT3(0, 0, 1);

	m_rotationX = 0.0f;
	m_rotationY = 0.0f;
	m_rotationZ = 0.0f;
}


Camera::Camera(const Camera& other)
{
}


Camera::~Camera()
{
}


void Camera::SetPosition(float x, float y, float z)
{
	mPosition.x = x;
	mPosition.y = y;
	mPosition.z = z;
	return;
}


void Camera::SetRotation(float x, float y, float z)
{
	m_rotationX = x;
	m_rotationY = y;
	m_rotationZ = z;
	return;
}


XMFLOAT3 Camera::GetPosition()
{
	return mPosition;
}

XMFLOAT3 Camera::GetVectorOrientation()
{
	XMMATRIX rotationMatrix = XMMatrixRotationRollPitchYaw(m_rotationX, m_rotationY, m_rotationZ);
	XMFLOAT3 result;
	XMStoreFloat3(&result, XMVector3Transform(XMLoadFloat3(&mFront), rotationMatrix));
	return result;
}

XMFLOAT3 Camera::GetRotation()
{
	return XMFLOAT3(m_rotationX, m_rotationY, m_rotationZ);
}


void Camera::Render()
{
	XMVECTOR up, position, lookAt, zero;
	float yaw, pitch, roll;
	XMMATRIX rotationMatrix;

	// Set the yaw (Y axis), pitch (X axis), and roll (Z axis) rotations in radians.
	pitch = m_rotationX;// * 0.0174532925f;
	yaw   = m_rotationY;// * 0.0174532925f;
	roll  = m_rotationZ;// * 0.0174532925f;

	// Create the rotation matrix from the yaw, pitch, and roll values.
	rotationMatrix = XMMatrixRotationRollPitchYaw(pitch, yaw, roll);

	// Transform the lookAt and up vector by the rotation matrix so the view is correctly rotated at the origin.
	lookAt = XMVector3Transform(XMLoadFloat3(&mFront), rotationMatrix);
	up = XMVector3Transform(XMLoadFloat3(&mUp), rotationMatrix);

	XMStoreFloat4x4(&mFixedViewMatrix, XMMatrixLookAtLH(XMVectorZero(), lookAt, up));

	// Translate the rotated camera position to the location of the viewer.
	position = XMLoadFloat3(&mPosition);
	lookAt = position + lookAt;

	// Finally create the view matrix from the three updated vectors.
	XMStoreFloat4x4(&mViewMatrix, XMMatrixLookAtLH(position, lookAt, up));

	return;
}


XMFLOAT4X4* Camera::GetViewMatrix()
{
	return &mViewMatrix;
}

XMFLOAT4X4* Camera::GetFixedViewMatrix()
{
	return &mFixedViewMatrix;
}